package data;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;

import domain.ArticuloRepository;
import util.ArticuloDTO;
import util.ArticuloAssembler;
import domain.Articulo;

public class ArticuloRepositoryDAOImpl implements ArticuloRepository {
 
 private ArticuloDAO profDAO;
 
 ArticuloRepositoryDAOImpl(ArticuloDAO profDAO) {
   this.profDAO = profDAO;
 }
 
 public boolean insertArticulo(Articulo prof) {
   ArticuloDTO profDTO = ArticuloAssembler.CreateDTO(prof);
   return (profDAO.insert(profDTO));
 }
 
 public boolean deleteArticulo(Articulo prof) {
   ArticuloDTO profDTO = ArticuloAssembler.CreateDTO(prof);
   return (profDAO.delete(profDTO));
 }
 
 public Articulo findArticulo(int id) {
   ArticuloDTO profDTO = profDAO.findById(id);
   if (profDTO!=null) {
     Articulo prof = new Articulo();
     System.out.println(profDTO.getNombre());
     ArticuloAssembler.Update(prof,profDTO);
     return prof;
   }
   return null;
 }
 
 public boolean updateArticulo(Articulo prof) {
   ArticuloDTO profDTO = ArticuloAssembler.CreateDTO(prof);
   return (profDAO.update(profDTO));
 }
 
 public Collection findAllArticulo() {
   Collection profsDTO = profDAO.findAll();
   List profList = new ArrayList();
   Iterator itr = profsDTO.iterator();
   while (itr.hasNext()) {
     Articulo prof = new Articulo();
     ArticuloDTO profDTO = (ArticuloDTO)itr.next();
     ArticuloAssembler.Update(prof,profDTO);
     profList.add(prof);
   }
   return profList;
 }
}